package com.linQing.waterWork.controller;

import com.linQing.waterWork.annotation.RepeatSubmitLimit;
import com.linQing.waterWork.exception.ServiceCode;
import com.linQing.waterWork.exception.ServiceException;
import com.linQing.waterWork.modle.dto.HourQuartZ.EnergyAnalysisDTO;
import com.linQing.waterWork.modle.vo.DataInfoListVo;
import com.linQing.waterWork.modle.vo.EquipmentStatusVO;
import com.linQing.waterWork.modle.vo.QueryWaterAndElectricity;
import com.linQing.waterWork.service.mongodb.EquipmentStatusService;
import com.linQing.waterWork.service.sql.HourquartzService;
import com.linQing.waterWork.service.sql.SwsDatainfoService;
import com.linQing.waterWork.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

import static com.linQing.waterWork.web.JsonResult.ok;

/**
 * @version 1.0.0
 * @program: linqing
 * @description: TODO 大屏页面相关接口
 * @author: lsk
 * @create: 2024-04-16 10:38
 * @since jdk1.8
 **/
@Api(value = "cockpit",tags = "大屏页面相关接口")
@RestController
@RequestMapping("/cockpit")
@Slf4j
public class CockpitController {

    @Autowired
    private SwsDatainfoService swsDatainfoService;


    @Resource
    private HourquartzService hourquartzService;
    @Resource
    private MongoTemplate mongoTemplate;

    @Resource
    private EquipmentStatusService equipmentStatusService;

    // 今日水/电/能耗分析
    @GetMapping("/equipmentStatus")
    @ApiOperation("3#实时能耗分析")
    public JsonResult<EquipmentStatusVO> getEquipmentStatus(@RequestParam String equipmentId) {
        log.debug("开始执行设备状态信息获取方法");
        EquipmentStatusVO equipmentStatus = equipmentStatusService.getEquipmentStatus(equipmentId);
        log.debug("即将返回数据: {}", equipmentStatus);
        return JsonResult.ok(equipmentStatus);
    }


    // 年/月/日用水/电分析
    @GetMapping ("/energyAnalysis")
    @ApiOperation("年月日能耗分析")
    public JsonResult<List<QueryWaterAndElectricity>> queryWaterAndElectricityByTime(
                                                                                        @RequestParam String equipmentId) {

        EnergyAnalysisDTO request = new EnergyAnalysisDTO();
        request.setEquipmentId(equipmentId);
        log.debug("设备编号: {}", equipmentId);
        request.setTime(new Date());
        List<QueryWaterAndElectricity> list = hourquartzService.queryWaterAndElectricOfDay(request);
        log.debug("将处理好的数据返回给前端: {}", list);
        return JsonResult.ok(list);

    }

    @ApiOperation("查询对应设备参数")
    @GetMapping("/data")
    @RepeatSubmitLimit(businessKey = "pageAllToDataInfo",businessParam = "#pageAllToDataInfo",time = 10)
    public JsonResult<List<DataInfoListVo>> pageAllToDataInfo(){
        return ok( swsDatainfoService.selectDataInfoByPage());
    }




}

